package com.geen.tuoke.ui.dialog

import android.content.Context
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import com.geen.tuoke.R
import com.geen.tuoke.databinding.DialogTimeIntervalBinding
import com.geen.tuoke.utils.ext.dp2px
import com.geen.tuoke.widget.dialog.DialogViewHolder
import com.geen.tuoke.widget.dialog.XXDialog
import com.qmuiteam.qmui.kotlin.onClick

/**
 * @Desc 时间间隔的弹窗
 */
class DialogTimeInterval(
    context: Context,
    private var onConfirm: (time: Int) -> Unit
) : XXDialog(context, R.layout.dialog_time_interval) {

    private var mBinding: DialogTimeIntervalBinding? = null
    var tvList = listOf<TextView>()

    init {
        setWidthAndHeight(dp2px(288f), 0)
        setCanceledOnTouchOutside(false)

        mBinding?.run {

            tvList = listOf<TextView>(tvTime5, tvTime10, tvTime15, tvTime30, tvTime60, tvTime90)
            tvTime10.isSelected = true


            tvList.forEach {
                it.onClick {
                    tvList.forEach { it.isSelected = false }
                    it.isSelected = true
                    dismiss()
                    onConfirm((it.tag as String).toInt())
                }
            }
        }

    }
    fun setData(time: Int): XXDialog{
        mBinding?.run {
            tvList.forEach { it.isSelected =  ((it.tag) as String ) .toInt()==time }
        }
        return  this
    }

    override fun convert(holder: DialogViewHolder) {
        mBinding = DataBindingUtil.bind(holder.convertView)

    }



}